import { useRequest } from 'umi';
import { ILoadMapTypeAll } from '@/common';
import { BGbusinessCategory, FSBG_STATE_QC, generateRandomNumber } from '../common/Format';
import { useCallback, useMemo, useState } from 'react';
import { getLoadMapList, getTenantID, requestFunComponFiex, getCompanyID, getUserID, getPosIDs, getUserDepID } from '@/utils';
import {
  ExpertManageTabSwitch,
  clarifyTabSwitch,
  expertTabSwitch,
  supplierOneTabSwitch,
  supplierTabSwitch,
  supplierTwoTabSwitch,
} from '../mconfig/ManageTabSwitch';
import moment from 'moment';
import { ManageCommonAPI } from '@/pages/type';
import { getBaseUrl } from '@/services/urlconst';

const baseUrl = getBaseUrl();

export const findSourceFailureBidSev = () => {
  const request = useRequest(
    (payload: any) => {
      let bodyParams = { ...payload };
      let reqUrl = `${baseUrl}/purchaseSourceController/getAbortiveChild`;
      return requestFunComponFiex('POST', reqUrl, bodyParams);
    },
    {
      manual: true,
    },
  );
  return {
    findSourceFailureBidRun: request.run,
    findSourceFailureBidLoading: request.loading,
  };
};

/** 采购实施详情接口 */
export const findSourceInfoService = () => {
  const request = useRequest(
    (payload: any) => {
      let bodyParams = { ...payload };
      let reqUrl = `${baseUrl}/purchaseSourceController/getSourceById/${bodyParams?.id}/${getUserID()}`;
      return requestFunComponFiex('GET', reqUrl, {});
    },
    {
      manual: true,
    },
  );
  return {
    findSourceInfoRun: request.run,
    findSourceInfoLoading: request.loading,
  };
};

/** 采购实施【公告详情接口】 */
export const findSourceInviteService = () => {
  const request = useRequest(
    (payload: any) => {
      // let bodyParams = { ...payload };
      // let reqUrl = `${baseUrl}/purchaseSourceController/getBidById/${bodyParams?.id}/${getUserID()}`;
      // return requestFunComponFiex('GET', reqUrl, {});

      let bodyParams = { ...payload };
      let reqUrl = `${baseUrl}/purchaseSourceController/getBidById`;
      return requestFunComponFiex('POST', reqUrl, bodyParams);
    },
    {
      manual: true,
    },
  );
  return {
    findSourceInviteRun: request.run,
    findSourceInviteLoading: request.loading,
  };
};

/** 采购实施【延期情况接口】 */
export const postponeService = () => {
  const request = useRequest(
    (payload: any) => {
      let bodyParams = { ...payload };
      let reqUrl = `${baseUrl}/purchaseSourceController/editExtensionBid`;
      return requestFunComponFiex('PUT', reqUrl, bodyParams);
    },
    {
      manual: true,
    },
  );
  return {
    postponeRun: request.run,
    postponeLoading: request.loading,
  };
};

/** 获取采购需求物料数据 【// TODO: 梁豪杰 待做权限判断 寻源模拟数据】 */
// export const findNeedMaterialService = () => {
//   const request = useRequest(
//     (payload: any) => {
//       let reqUrl = `${baseUrl}/purchaseNeedMaterialController/dataGrid/createCompanyID`;
//       let params = {
//         ...payload,
//         createCompanyID: getCompanyID(),
//       };
//       return requestFunComponFiex('POST', reqUrl, params);
//     },
//     {
//       manual: true,
//     },
//   );
//   return {
//     findNeedMaterialRun: request.run,
//     findNeedMaterialLoading: request.loading,
//     findNeedMaterialProps: (request as any).tableProps,
//   };
// };

/** 查询寻源专家信息 */
export const findSourceExpertsService = () => {
  const request = useRequest(
    (payload: any) => {
      let reqUrl = `${baseUrl}/purchaseSourceExpertsController/details`;
      return requestFunComponFiex('POST', reqUrl, payload);
    },
    {
      manual: true,
    },
  );
  return {
    findSourceExpertsRun: request.run,
    findSourceExpertsLoading: request.loading,
  };
};

/** 请求专家列表信息 */
export const getExpertsDataGrid = (curRes: Record<string, any>) => {
  /** 获取数据字典 */
  const loadMdicIds: string[] = [
    `${getTenantID()}${ILoadMapTypeAll.EXPERTS_TYPE}`,
    `${getTenantID()}${ILoadMapTypeAll.EXPERTS_LEVEL}`,
    `${getTenantID()}${ILoadMapTypeAll.EXPERTS_INDUSTRY_TYPE}`,
  ];

  /** 获取数据字典loadMdicMap */
  const { loadMapInfo, mapLoading } = getLoadMapList(loadMdicIds);

  /***保存当前的搜索参数**/
  const [manageTableParams, setManageTableParams] = useState<Record<string, any>>({});

  /** 权限参数 */
  const curResObj = {};

  /** 获取数据列表 */
  const { loading, run, refresh, tableProps, data } = useRequest(
    (opt) => {
      const requestBody: Record<string, any> = {
        // current: 1,
        // pageSize: 10,
        sort: 'createTime',
        order: 'desc',
        dicTypeIds: loadMdicIds?.toString(),
        isBlack: 0,
        ...curResObj,
        ...opt,
      };

      /** 请求地址 */
      const reqUrl = `${baseUrl}/expertInfoController/dataGrid/${requestBody?.params}`;

      /** 请求 */
      // return requestFunComponFiex('POST', reqUrl, requestBody);
    },
    {
      manual: false, //页面初始请求为 true
      paginated: true,
      defaultPageSize: 10,
    },
  );

  /***页面数据及分页信息**/
  const tableValues = useMemo(() => {
    return {
      data,
      pagination: tableProps?.pagination,
    };
  }, [data, tableProps]);

  /** 重新请求方法 */
  const reloadRequest = useCallback((reqParams) => {
    run({ ...reqParams });
  }, []);

  return {
    loading,
    mapLoading,
    loadMapInfo,
    reloadRequest,
    manageTableParams,
    ...tableValues,
  };
};

/** 请求抽取专家列表信息 */
export const getExtractExpertsDataGrid = (Callback: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload) => {
      let bodyParams = {
        isOpen: 1,
        ...payload,
      };

      let reqUrl = `${baseUrl}/expertInfoController/randExpert`;
      return requestFunComponFiex('POST', reqUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );

  const data = useMemo(() => {
    if (request.data?.obj) {
      request.data?.obj?.forEach((item) => {
        // 给一个新值，然后删除id，在新增的时候不需要，只要expertID字段
        item.expertID = item?.id;
        item.mockID = generateRandomNumber('experts_');
        item.expertFlag = 0;
        delete item?.['id'];
      });
      return request.data?.obj;
    } else {
      return [];
    }
  }, [request.data?.obj]);

  return {
    extractExpertsRun: request?.run,
    extractExpertsLoading: request?.loading,
    extractExpertsData: data,
  };
};

/** 添加招标公告 */
export const addBidService = (Callback: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload: any) => {
      let reqUrl = `${baseUrl}/purchaseSourceController/addBid`;
      let params = {
        ...payload,
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
      };
      return requestFunComponFiex('PUT', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    addBidRun: request.run,
    addBidLoading: request.loading,
  };
};

/** 编辑招标公告 */
export const editBidService = (Callback: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload: any) => {
      let reqUrl = `${baseUrl}/purchaseSourceController/editBid`;
      let params = {
        ...payload,
        modifyerID: getUserID(),
        modifyPositionID: getPosIDs(),
        modifyDepartmentID: getUserDepID(),
        modifyCompanyID: getCompanyID(),
      };
      return requestFunComponFiex('PUT', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    editBidRun: request.run,
    editBidLoading: request.loading,
  };
};

/** 提交招标公告 */
export const applyBidService = (Callback: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload: any) => {
      let reqUrl = `${baseUrl}/purchaseSourceController/editState`;
      let params = {
        ...payload,
        modifyerID: getUserID(),
        modifyPositionID: getPosIDs(),
        modifyDepartmentID: getUserDepID(),
        modifyCompanyID: getCompanyID(),
      };
      return requestFunComponFiex('PUT', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    applyBidRun: request.run,
    applyBidLoading: request.loading,
  };
};

/** 获取该包是否有澄清【澄清详情】 */
export const getPackClarifySerivice = (Callback: (res, val, bol) => void, curRes) => {
  const [num, setNum] = useState({});
  const [flag, setFlag] = useState(false);
  const request = useRequest(
    (payload: any, val, val2, val3 = true) => {
      setNum({ totalNum: val, currentNum: val2 });
      setFlag(val3);
      let params = {
        ...payload,
        ...clarifyTabSwitch(curRes),
        sort: 'createTime',
        order: 'asc',
      };

      let reqUrl = `${baseUrl}/purchaseSourceClarifyController/dataGrid/${params?.params}`;

      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: (res) => {
        return Callback(res, num, flag);
      },
    },
  );
  return {
    getPackClarifyRun: request.run,
    getPackClarifyLoading: request.loading,
    reloadDetailInfo: request?.refresh,
  };
};

/** 获取澄清详情 */
export const getClarifyServices = (Callback: (res) => void) => {
  const request = useRequest(
    (payload: any) => {
      let reqUrl = `${baseUrl}/purchaseSourceClarifyController/getSourceClarifyByID/${payload?.id}/${getUserID()}`;

      return requestFunComponFiex('GET', reqUrl);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    getClarifyRun: request?.run,
    getClarifyLoading: request?.loading,
    reloadDetailInfo: request?.refresh,
  };
};

/** 暂存澄清 */
export const addClarifySerivice = (Callback: (res) => void) => {
  const request = useRequest(
    (payload: any, val) => {
      let params = {
        ...payload,
        businessType: `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1009`,
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
        clarifyCode: `HLZB00KCCQ${moment().format('YYMM')}`,
      };

      let reqUrl = `${baseUrl}/purchaseSourceClarifyController/add`;

      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    addClarifyRun: request.run,
    addClarifyLoading: request.loading,
  };
};
/** 编辑澄清 */
export const editClarifySerivice = (Callback: (res) => void) => {
  const request = useRequest(
    (payload: any, val) => {
      let params = {
        ...payload,
        businessType: `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1009`,
        modifyerID: getUserID(),
        modifyPositionID: getPosIDs(),
        modifyDepartmentID: getUserDepID(),
        modifyCompanyID: getCompanyID(),
      };

      let reqUrl = `${baseUrl}/purchaseSourceClarifyController/edit`;

      return requestFunComponFiex('PUT', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    editClarifyRun: request.run,
    editClarifyLoading: request.loading,
  };
};
/** 删除澄清 */
export const deleteClarifySerivice = (Callback: (res) => void) => {
  const request = useRequest(
    (payload: any) => {
      let params = {
        ...payload,
        cancelerID: getUserID(),
        cancelPositionID: getPosIDs(),
        cancelDepartmentID: getUserDepID(),
        cancelCompanyID: getCompanyID(),
      };

      let reqUrl = `${baseUrl}/purchaseSourceClarifyController/delClarify`;

      return requestFunComponFiex('DELETE', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    deleteClarifyRun: request.run,
    deleteClarifyLoading: request.loading,
  };
};

/** 批量暂存评标委员会 */
export const BatchAddExpertsServices = (cb) => {
  const request = useRequest(
    (payload: any) => {
      let params = {
        ...payload,
      };
      let reqUrl = `${baseUrl}/purchaseSourceExpertController/batchAdd`;
      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );
  return {
    BatchAddExpertsRun: request.run,
    BatchAddExpertsLoading: request.loading,
  };
};

/** 暂存评标委员会 */
export const addExpertsSerivice = (Callback: (res) => void) => {
  const request = useRequest(
    (payload: any) => {
      let params = {
        ...payload,
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
        state: `${getTenantID()}${ILoadMapTypeAll?.EXPERT_BUSINESSTYPE}1000`,
      };

      // let reqUrl = `${baseUrl}/purchaseSourceExpertController/add`;
      let reqUrl = `${baseUrl}/purchaseSourceExpertController/addExpert`;

      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    addExpertsRun: request.run,
    addExpertsLoading: request.loading,
  };
};
/** 详情评标委员会列表 */
export const getExpertsSerivice = (Callback: (res, isFlagState) => void, curRes) => {
  let [isFlagState, setIsFlagState] = useState();
  const request = useRequest(
    (payload: any, isFlag = false) => {
      let params = {
        ...payload,
        ...expertTabSwitch(curRes),
      };
      setIsFlagState(isFlag);
      let reqUrl = `${baseUrl}/purchaseSourceExpertController/dataGrid/${params?.params}/${getUserID()}`;
      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: (res) => {
        Callback(res, isFlagState);
      },
    },
  );
  return {
    getExpertsRun: request.run,
    getExpertsLoading: request.loading,
  };
};
/** 编辑评标委员会 */
export const editExpertsSerivice = (Callback: (res) => void) => {
  const request = useRequest(
    (payload: any) => {
      let params = {
        ...payload,
        modifyerID: getUserID(),
        modifyPositionID: getPosIDs(),
        modifyDepartmentID: getUserDepID(),
        modifyCompanyID: getCompanyID(),
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
        state: `${getTenantID()}${ILoadMapTypeAll?.EXPERT_BUSINESSTYPE}1000`,
      };

      let reqUrl = `${baseUrl}/purchaseSourceExpertController/edit`;

      return requestFunComponFiex('PUT', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: Callback,
    },
  );
  return {
    editExpertsRun: request.run,
    editExpertsLoading: request.loading,
  };
};

/**根据申请ID获取采购人评标代表数据*/
export const ApplyIdGetExpertDataGrid = (curRes) => {
  const { run, loading } = useRequest(
    (request) => {
      let bodyParams: Record<string, any> = {
        current: 1,
        pageSize: 9999,
        sort: 'createTime', //必填
        order: 'desc', //必填
        dicTypeIds: `${getTenantID()}${ILoadMapTypeAll.EXPERT_BUSINESSTYPE}`,
        state: `${getTenantID()}${ILoadMapTypeAll.EXPERT_BUSINESSTYPE}1000,${getTenantID()}${ILoadMapTypeAll.EXPERT_BUSINESSTYPE}1001,${getTenantID()}${
          ILoadMapTypeAll.EXPERT_BUSINESSTYPE
        }1002`,
        ...ExpertManageTabSwitch(curRes),
        ...request,
      };
      let reqUrl = `${baseUrl}/purchaseSourceExpertController/dataRepresentativeGrid/${bodyParams?.params}`;

      /***发起请求数据接口**/
      return requestFunComponFiex('POST', reqUrl, bodyParams);
    },
    {
      manual: true,
      // paginated: true,
      // defaultPageSize: 10,
    },
  );

  return {
    ApplyIdGetExpertRun: run,
    ApplyIdGetExpertLoading: loading,
  };
};

/** 请求供应商列表信息 */
export const getSupplierDataGrid = (curRes: Record<string, any>) => {
  /** 获取数据字典 */
  const loadMdicIds: string[] = [
    `${getTenantID()}${ILoadMapTypeAll.MATERIAL_TYPE}`,
    `${getTenantID()}${ILoadMapTypeAll.PURCHASE_CATEGORY}`,
    `${getTenantID()}${ILoadMapTypeAll.COMPANY_SCALE}`, //企业规模
    `${getTenantID()}${ILoadMapTypeAll.QUALIFICA_TYPE}`, //企业类型
    `${getTenantID()}${ILoadMapTypeAll.SUPPLIER_STATE}`, //企业类型
  ];

  /** 获取数据字典loadMdicMap */
  const { loadMapInfo, mapLoading } = getLoadMapList(loadMdicIds);

  /***保存当前的搜索参数**/
  const [manageTableParams, setManageTableParams] = useState<Record<string, any>>({});

  /** 权限参数 */
  const curResObj = supplierTabSwitch(curRes);

  let creditList: string[] = ['12100000MB2001605R', '12110000MB1N5794X2'];

  /** 获取数据列表 */
  const { loading, run, refresh, tableProps, data, pagination } = useRequest(
    (opt) => {
      const requestBody: Record<string, any> = {
        // current: 1,
        // pageSize: 10,
        sort: 'createTime',
        order: 'desc',
        dicTypeIds: loadMdicIds?.toString(),
        creditID: creditList?.toString(),
        selectSign: false,
        supplierState: 0,
        ...curResObj,
        ...opt,
      };

      setManageTableParams(requestBody);

      /** 请求地址 */
      const reqUrl = `${baseUrl}/supplierInfoController/dataGrid/${requestBody?.params}`;

      /** 请求 */
      return requestFunComponFiex('POST', reqUrl, requestBody);
    },
    {
      manual: false, //页面初始请求为 true
      paginated: true,
      defaultPageSize: 10,
    },
  );

  /***页面数据及分页信息**/
  const tableValues = useMemo(() => {
    return {
      data,
      pagination: tableProps?.pagination,
    };
  }, [data, tableProps]);

  /** 重新请求方法 */
  const reloadRequest = useCallback((reqParams) => {
    run({ ...reqParams });
  }, []);

  return {
    loading,
    mapLoading,
    loadMapInfo,
    reloadRequest,
    manageTableParams,
    supplierTableProps: pagination,
    ...tableValues,
  };
};
/** 开评标暂存1号接口 */
export const addSupplierOneSerivice = (Callback: (res, isTwoAdd) => void) => {
  let [isTwoAdd, setIsTwoAdd] = useState({});
  const request = useRequest(
    (payload: any, { isAdd = false, addData = {} }) => {
      let params = {
        ...payload,
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
        businessType: `${getTenantID()}${ILoadMapTypeAll?.EVAL_BUSINESSTYPE}1000`,
        state: `${getTenantID()}${ILoadMapTypeAll?.EVAL_STATE}1000`,
      };
      setIsTwoAdd({ isAdd, addData });
      let reqUrl = `${baseUrl}/purchaseSourceSupplierController/add`;
      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: (res) => {
        Callback(res, isTwoAdd);
      },
    },
  );
  return {
    addSupplierOneRun: request.run,
    addSupplierOneLoading: request.loading,
  };
};
/** 开评标暂存2号接口 */
export const addSupplierTwoSerivice = (Callback: (res, isTwoAdd) => void) => {
  let [isTwoAdd, setIsTwoAdd] = useState({});
  const request = useRequest(
    (payload: any, { isAdd = false, addData = {} }) => {
      let params = {
        ...payload,
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
        businessType: `${getTenantID()}${ILoadMapTypeAll?.EVAL_BUSINESSTYPE}1000`,
        state: `${getTenantID()}${ILoadMapTypeAll?.EVAL_STATE}1000`,
      };
      setIsTwoAdd({ isAdd, addData });
      let reqUrl = `${baseUrl}/purchaseSourcePrepareController/addSourcePrepare`;
      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: (res) => {
        Callback(res, isTwoAdd);
      },
    },
  );
  return {
    addSupplierTwoRun: request.run,
    addSupplierTwoLoading: request.loading,
  };
};
/** 开评标详情1号接口 */
export const getSupplierOneSerivice = (cb, curRes) => {
  let [isFlag, setIsFlag] = useState<boolean>(false);
  const request = useRequest(
    (payload: any, paramsFlag = false) => {
      setIsFlag(paramsFlag);
      let params = {
        ...payload,
        ...supplierOneTabSwitch(curRes),
      };
      let reqUrl = `${baseUrl}/purchaseSourceSupplierController/dataGrid/${params?.params}`;
      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: (res) => {
        cb(res, isFlag);
      },
    },
  );
  return {
    getSupplierOneRun: request.run,
    getSupplierOneLoading: request.loading,
  };
};
/** 开评标详情2号接口 */
export const getSupplierTwoSerivice = (cb, curRes) => {
  const request = useRequest(
    (payload: any) => {
      let params = {
        ...payload,
        ...supplierTwoTabSwitch(curRes),
      };
      let reqUrl = `${baseUrl}/purchaseSourcePrepareController/dataGrid/${params?.params}`;
      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );
  return {
    getSupplierTwoRun: request.run,
    getSupplierTwoLoading: request.loading,
  };
};
/** 开评标编辑1号接口 */
export const editSupplierOneSerivice = (cb: (res: Record<string, any>, paramsObj) => void) => {
  let [isParamsObj, setIsParamsObj] = useState<Record<string, any>>({});
  const request = useRequest(
    (payload: any, ParamsObj) => {
      setIsParamsObj(ParamsObj);
      let params = {
        ...payload,
        modifyerID: getUserID(),
        modifyPositionID: getPosIDs(),
        modifyDepartmentID: getUserDepID(),
        modifyCompanyID: getCompanyID(),
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
        businessType: `${getTenantID()}${ILoadMapTypeAll?.EVAL_BUSINESSTYPE}1000`,
      };

      let reqUrl = `${baseUrl}/purchaseSourceSupplierController/editSourceSupplier`;
      return requestFunComponFiex('PUT', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: (res) => {
        cb(res, isParamsObj);
      },
    },
  );
  return {
    editSupplierOneRun: request.run,
    editSupplierOneLoading: request.loading,
  };
};
/** 开评标编辑2号接口 */
export const editSupplierTwoServices = (cb) => {
  const [isFlag, setIsFlag] = useState<boolean>(false);
  const request = useRequest(
    (payload: any, flag = false) => {
      setIsFlag(flag);
      let params = {
        ...payload,
        modifyerID: getUserID(),
        modifyPositionID: getPosIDs(),
        modifyDepartmentID: getUserDepID(),
        modifyCompanyID: getCompanyID(),
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
        businessType: `${getTenantID()}${ILoadMapTypeAll?.EVAL_BUSINESSTYPE}1000`,
      };

      let reqUrl = `${baseUrl}/purchaseSourcePrepareController/editSourcePrepare`;
      return requestFunComponFiex('PUT', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: (res) => {
        cb(res, isFlag);
      },
    },
  );
  return {
    editSupplierTwoRun: request.run,
    editSupplierTwoLoading: request.loading,
  };
};

/** 定标新增接口 */
export const addCalibrateServices = (cb: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload: any) => {
      let params = {
        ...payload,
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
        businessType: '100199031005',
        state: `${getTenantID()}${ILoadMapTypeAll?.CALIBRATE_STATE}1000`,
        calibrateCode: `HLZB00KCDB${moment().format('YYMM')}`,
      };

      let reqUrl = `${baseUrl}/purchaseSourceCalibrateController/addSourceCalibrate`;
      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );
  return {
    addCalibrateRun: request.run,
    addCalibrateLoading: request.loading,
  };
};

/** 定标编辑接口 */
export const editCalibrateServices = (cb: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload: any) => {
      let params = {
        ...payload,
        modifyerID: getUserID(),
        modifyPositionID: getPosIDs(),
        modifyDepartmentID: getUserDepID(),
        modifyCompanyID: getCompanyID(),
        // businessType: `${getTenantID()}${ILoadMapTypeAll?.EVAL_BUSINESSTYPE}1000`,
        // state: `${getTenantID()}${ILoadMapTypeAll?.EVAL_STATE}1000`,
      };

      let reqUrl = `${baseUrl}/purchaseSourceCalibrateController/editSourceCalibrate`;
      return requestFunComponFiex('PUT', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );
  return {
    editCalibrateRun: request.run,
    editCalibrateLoading: request.loading,
  };
};

/** 定标详情 */
export const getCalibrateSerivice = (cb) => {
  const request = useRequest(
    (payload: any) => {
      let params = {
        ...payload,
      };
      let reqUrl = `${baseUrl}/purchaseSourceCalibrateController/getSourceCalibrateById/${params?.id}/${getUserID()}`;
      return requestFunComponFiex('GET', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );
  return {
    getCalibrateRun: request.run,
    getCalibrateLoading: request.loading,
    reloadDetailInfo: request?.refresh,
  };
};

/**定标完成后同步数据*/
export const syncApplyPackSerivice = (cb) => {
  const request = useRequest(
    (payload: any) => {
      let params = {
        ...payload,
      };
      let reqUrl = `${baseUrl}/purchaseSourceCalibrateController/updateNeedMaterialNum`;
      return requestFunComponFiex('POST', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );
  return {
    syncApplyPackRun: request.run,
    syncApplyPackLoading: request.loading,
  };
};

/** 判断澄清是否还有未审核的 */
export const sourceUpdateStateService = (callback: (res: any) => void) => {
  const sourceUpdateState = useRequest(
    (payload: any) => {
      let params = {
        ...payload,
        state: `${getTenantID()}${ILoadMapTypeAll?.PROCURECLARFY_STATE}1002,${getTenantID()}${ILoadMapTypeAll?.PROCURECLARFY_STATE}1003`,
      };
      let reqUrl = `${baseUrl}/purchaseSourceController/checkBidFlag`;
      return requestFunComponFiex('PUT', reqUrl, params);
    },
    {
      manual: true,
      onSuccess: callback,
    },
  );
  return {
    sourceUpdateStateRun: sourceUpdateState.run,
    sourceUpdateStateLoading: sourceUpdateState.loading,
  };
};

// ==========================变更采购方式==============================START
/** 添加 */
export const addPurchaseWayChangeServices = (cb) => {
  const request = useRequest(
    (payload) => {
      let bodyParams = {
        ...payload,
        businessType: BGbusinessCategory(),
        state: FSBG_STATE_QC(),
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
        changeCode: `HLZB00KCBG${moment().format('YYMM')}`,
      };

      let reqUrl = `${baseUrl}/purchaseSourceChangeController/add`;
      return requestFunComponFiex('POST', reqUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );

  return {
    addPurchaseWayChangeRun: request?.run,
    addPurchaseWayChangeLoading: request?.loading,
  };
};
/** 详情 */
export const getPurchaseWayChangeServices = (cb) => {
  const request = useRequest(
    (payload) => {
      let bodyParams = {
        ...payload,
      };

      let reqUrl = `${baseUrl}/purchaseSourceChangeController/getSourceChangeById/${bodyParams?.id}/${getUserID()}`;
      return requestFunComponFiex('GET', reqUrl);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );

  return {
    getPurchaseWayChangeRun: request?.run,
    getPurchaseWayChangeLoading: request?.loading,
  };
};
/** 编辑采购变更申请 */
export const editPurchaseWayChangeServices = (cb) => {
  const request = useRequest(
    (payload) => {
      let bodyParams = {
        ...payload,
        businessType: BGbusinessCategory(),
        state: FSBG_STATE_QC(),
        modifyerID: getUserID(),
        modifyPositionID: getPosIDs(),
        modifyDepartmentID: getUserDepID(),
        modifyCompanyID: getCompanyID(),
      };

      let reqUrl = `${baseUrl}/purchaseSourceChangeController/edit`;
      return requestFunComponFiex('PUT', reqUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );

  return {
    editPurchaseWayChangeRun: request?.run,
    editPurchaseWayChangeLoading: request?.loading,
  };
};
// ==========================变更采购方式==============================END

// ==========================流标 - 公告==============================START8
export const fetchFailureBidServices = (cb) => {
  const request = useRequest(
    (payload) => {
      let bodyParams = {
        ...payload,
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
      };
      let reqUrl = `${baseUrl}/purchaseSourceController/failureBid`;
      return requestFunComponFiex('POST', reqUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );

  return {
    fetchFailureBidRun: request?.run,
    fetchFailureBidLoading: request?.loading,
  };
};
// ==========================流标 - 公告==============================END

/**
 * 查看当前流程进度
 * @controller 业务controller
 * @returns
 */
export const getImageByProcInstIDService = (callBack: (res: any) => void, cantroller) => {
  const getImageByProcInstID = useRequest(
    (params: any) => {
      let personUrl = `${baseUrl}/${cantroller}/getImageByProcInstID/${params?.procInstID}`;
      return requestFunComponFiex('GET', personUrl, {});
    },
    {
      manual: true,
      onSuccess: callBack,
    },
  );

  const data = useMemo(() => {
    return getImageByProcInstID?.data;
  }, [getImageByProcInstID?.data]);

  return {
    getImageByProcInstIDRun: getImageByProcInstID?.run,
    getImageByProcInstIDLoading: getImageByProcInstID?.loading,
    getImageByProcInstIDData: data,
  };
};

/**
 * 定标推动档案
 * */
export const syncPDFtoOAServices = (cb: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload) => {
      let reqParams = { ...payload };
      let reqUrl = `${baseUrl}/purchaseSourceCalibrateController/syncWorkFlow`;
      return requestFunComponFiex('POST', reqUrl, reqParams);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );

  return {
    syncPDFtoOARun: request?.run,
    syncPDFtoOALoading: request?.loading,
  };
};

/**
 * 定标推动档案
 * */
export const syncPDFtoOAClarifyServices = (cb: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload) => {
      let reqParams = { ...payload };
      let reqUrl = `${baseUrl}/purchaseSourceClarifyController/syncWorkFlow`;
      return requestFunComponFiex('POST', reqUrl, reqParams);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );

  return {
    syncPDFtoOARun: request?.run,
    syncPDFtoOALoading: request?.loading,
  };
};

/**
 * 添加专家到专家库
 * */
export const addExpertService = (cb: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload) => {
      let reqParams = {
        ...payload,
        createrID: getUserID(),
        createPositionID: getPosIDs(),
        createDepartmentID: getUserDepID(),
        createCompanyID: getCompanyID(),
      };
      let reqUrl = `${baseUrl}/purchaseSourceExpertController/addExpertInfo`;
      return requestFunComponFiex('POST', reqUrl, reqParams);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );

  return {
    addExpertRun: request?.run,
    addExpertLoading: request?.loading,
  };
};

export const SelectBankService = (callback = (res) => {}) => {
  /** 获取列表数据  */
  const { tableProps, data, loading, run, refresh } = useRequest(
    (opt: ManageCommonAPI.IGridRequestType) => {
      const requestBody: Record<string, any> = {
        current: 1,
        pageSize: 10,
        sort: 'createTime',
        order: 'desc',
        selectSign: false,
        ...opt,
      };

      const requestURL = `${baseUrl}/supplierInfoController/getBankByName`;
      return requestFunComponFiex('POST', requestURL, requestBody);
    },
    {
      manual: false, //页面初始请求为 true
      paginated: true,
      defaultPageSize: 10,
      onSuccess: callback,
    },
  );

  /* 获取页面数据 */
  const getBankRun = (otherRequest: ManageCommonAPI.IGridRequestType | any) => {
    const request: ManageCommonAPI.IGridRequestType | any = { ...otherRequest };
    run({ ...request });
  };

  /**
   * 页面列表
   */
  let returnTableProps = useMemo(() => {
    return {
      datas: data,
      paginations: tableProps?.pagination,
    };
  }, [data, tableProps]);

  return {
    loading,
    getBankRun,
    reloadRefresh: refresh,
    ...returnTableProps,
  };
};
